import { NotFoundException } from '@nestjs/common';
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Controller, Get, UseInterceptors } from '@nestjs/common';

import { PageAlias, PagePathMapping } from '@libs/common/router';
import { ReactRootView } from '@libs/server-side/decorators';
import { RenderReactInterceptor } from '@libs/server-side/interceptors';
import { ServerSideConfigService } from '@libs/server-side/services';

import { ResumeTmplListView } from '../views/tmpl-list/tmpl-list.server';
import { ResumeTmplDetailView } from '../views/tmpl-detail/tmpl-detail.server';
import { TemplateDetailData, TemplateDetailInitData } from '../models/template-detail.types';
import { ModuleComponentType } from '../components/resume-detail/template/module-component.enum';
import { getValueFromYamlAsync } from '@libs/common/utils/yaml.utils';

@Controller()
@UseInterceptors(RenderReactInterceptor)
export default class ResumeTmplController {
    // eslint-disable-next-line no-useless-constructor
    constructor(private readonly serverSideConfig: ServerSideConfigService) {}

    @ReactRootView(ResumeTmplListView, PageAlias.ResumeTemplateList)
    @Get(PagePathMapping[PageAlias.ResumeTemplateList]?.path)
    public async List() {
        return { initData: 'a' };
    }

    @ReactRootView(ResumeTmplDetailView, PageAlias.ResumeTemplateDetail)
    @Get(PagePathMapping[PageAlias.ResumeTemplateDetail]?.path)
    public async Detail() {
        const templateData: TemplateDetailInitData = {
            name: 'Cool',
            data: await getValueFromYamlAsync<TemplateDetailData>('./me-data.yml', false),
        };

        if ((templateData.data?.toString()?.trim()?.length ?? -1) <= 0) {
            throw new NotFoundException();
        }

        return { initData: templateData };
    }
}
